from lib.request import request
from services.novel_service import NovelService
from services.novel_role_service import NovelRoleService
from lib.resp import resp_json


class NovelController:

    def __init__(*args, **kwargs) -> None:

        pass

    def novel_list(self):
        data = request().json()
        page = data.get("Page", 0)
        limit = data.get("Limit", 10)
        story_name = data.get("StoryName", "")
        ret_obj = NovelService().novel_list(story_name, page, limit)
        return resp_json(ret_obj)

    def novel_save(self):
        data = request().json()
        print("novel_save", data)
        novel_Id = data.get("NovelId", 0)
        save = {
            "Name": data.get("Name", ""),
            "UserId": data.get("UserId", 0),
            "Descript": data.get("Descript", ""),
            "Image": data.get("Image", ""),
            "Author": data.get("Author", ""),
        }
        ret_obj = NovelService().novel_save(novel_Id, data=save)
        return resp_json(ret_obj)

    def novel_delete(self):
        data = request().json()
        novel_id = data.get("NovelId", 0)
        ret_obj = NovelService().novel_delete(novel_id)
        return resp_json(ret_obj)

    def novel_role_list(self):
        data = request().json()
        page = data.get("Page", 0)
        limit = data.get("Limit", 10)
        role_name = data.get("RoleName", "")
        novel_id = data.get("NovelId", 0)
        ret_obj = NovelRoleService().role_list(
            novel_id, role_name=role_name, page=page, limit=limit
        )
        return resp_json(ret_obj)

    def novel_role_save(self):
        data = request().json()
        role_id = data.get("RoleId", 0)
        save = {
            "RoleName": data.get("RoleName", ""),
            "NovelId": data.get("NovelId", 0),
            "RoleImage": data.get("RoleImage", ""),
            "RolePrompt": data.get("RolePrompt", ""),
            "RoleLabel": data.get("RoleLabel", ""),
            "RoleDesc": data.get("RoleDesc", ""),
        }
        ret_obj = NovelRoleService().role_save(role_id, data=save)
        return resp_json(ret_obj)

    def novel_role_del(self):
        data = request().json()
        role_id = data.get("RoleId", 0)
        ret_obj = NovelRoleService().role_delete(role_id)
        return resp_json(ret_obj)
